<?php
// +-----------------------------------------------------------------------------------------------
// | 简易CMS
// +-----------------------------------------------------------------------------------------------
// | [请手动修改文件描述]
// +-----------------------------------------------------------------------------------------------
// | Author: IT果农 <htmambo@163.com> <http://www.haolie.net>
// +-----------------------------------------------------------------------------------------------
// | Version $Id$
// +-----------------------------------------------------------------------------------------------

namespace app\admin\model;
use CMS\Model;

/**
 * 插件模型
 */

class Menu extends Model {

    /**
     * 删除某个菜单前先检查一下该菜单是否还有子菜单，如果还有子菜单则不允许删除
     * @param \CMS\Model $obj
     */
    protected static function before_delete($obj = array()) {
        $options = $obj->getAllOptions();       //因为后面要执行查询操作，所以这里得保存一下现在的options
        $ids = $obj->getField('id');
        $child = $obj->where(array('pid' => array('IN', $ids)))->count();
        if ($child) {
            $obj->error = '指定的菜单还有子菜单未删除！';
            return false;
        }
        $obj->setOptions($options);         //恢复已经保存的options
        return true;
    }
}